<template>
  <el-dialog
    title="编辑呼吸机信息"
    :visible.sync="dialogVisible"
    :showClose="false"
    :before-close="cancelDialog"
    :close-on-click-modal="false"
  >
    <el-form class="form" label-width="120px">
      <el-form-item label="编号: ">
        <el-input v-model="dialogInfo.numbers" class="bianji" />
      </el-form-item>
      <el-form-item label="厂家名称: ">
        <el-input v-model="dialogInfo.respiratorManufacturers" class="bianji" />
      </el-form-item>
      <el-form-item label="厂家型号:">
        <el-input v-model="dialogInfo.respiratorNumber" class="bianji" />
      </el-form-item>
      <el-form-item label="采购日期:">
        <el-date-picker
          v-model="dialogInfo.procurementDate"
          type="date"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-form-item label="波特率 : ">
        <el-input v-model="dialogInfo.respiratorBaudrate" class="bianji" />
      </el-form-item>
      <el-form-item label="数据位 : ">
        <el-input v-model="dialogInfo.respiratorDatabits" class="bianji" />
      </el-form-item>
      <el-form-item label="停止位: ">
        <el-input v-model="dialogInfo.respiratorStopbits" class="bianji" />
      </el-form-item>
      <el-form-item label="校验位: ">
        <el-input v-model="dialogInfo.respiratorParity" class="bianji" />
      </el-form-item>
      <el-form-item label="状态 : ">
        <el-switch
          v-model="dialogInfo.status"
          class="switch-btn"
          inactive-text="禁用"
          active-text="启用"
          :active-value="1"
          :inactive-value="2"
          active-color="#02538C"
          inactive-color="#B9B9B9"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancelDialog">取 消</el-button>
      <el-button type="primary" @click="saveDialog">保 存</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {
  deparqueryList,
  respiratorDictonaryUpdate,
} from "@/api/table";

export default {
  name: "Lisecome",
  components: {},
  // 父组件 传 过来的 值
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
    dialogInfo: {
      type: Object,
      default: {},
    },
  },
  watch: {
    // 监听 弹窗显示， 可以用来写 请求接口
    dialogVisible: function (newVal, oldVal) {
      if (newVal) {
        console.log(newVal);
      }
    },
  },
  methods: {
    cancelDialog() {
      this.$emit("update:dialogVisible", false);
    },
    // 修改父组件传过来的值
    saveDialog() {
      respiratorDictonaryUpdate({
        id: this.dialogInfo.id,
        status: this.dialogInfo.status,
        respiratorManufacturers: this.dialogInfo.respiratorManufacturers,
        respiratorNumber: this.dialogInfo.respiratorNumber,
        procurementDate: this.dialogInfo.procurementDate,
        respiratorBaudrate: this.dialogInfo.respiratorBaudrate,
        respiratorDatabits: this.dialogInfo.respiratorDatabits,
        respiratorStopbits: this.dialogInfo.respiratorStopbits,
        respiratorParity: this.dialogInfo.respiratorParity,
        numbers:this.dialogInfo.numbers,
      }).then((res) => {
        if (res.code === 200) {
          this.$message({
            message: "保存成功",
            type: "success",
          });
          this.$emit("update:dialogVisible", false);
        }else{
          this.$message({
            message: "保存失败",
            type: "warning",
          });
        }
      });
    },
  },
};
</script>
<style lang='scss' scoped>
::v-deep .el-dialog{
  width: 600px;
}
</style>
